package com.gylang.sso.repository;

import com.gylang.sso.domain.SysMenu;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.Collection;
import java.util.List;

/**
 * @author gylang,
 * @data 2019/11/17 16:54,
 * @DESC
 */
public interface SysMenuRepository extends JpaRepository<SysMenu, Long>, JpaSpecificationExecutor<SysMenu> {

    List<SysMenu> findByIdIn(Collection<Long> IdList);

    @Query(value = "select m.* from sys_user u, sys_user_role ur, sys_role_menu rm, sys_menu m " +
            "where u.name=?1 and u.id=ur.user_id and ur.role_id=rm.role_id and rm.menu_id=m.id", nativeQuery = true)
    List<SysMenu> findByUserName(String userName);
}
